var orderdb = require('../../db/order.db')
var config = require('../../config')
var removecartitem = require("../browser/removecartitem")
var logger = require('../../logger')
var emit = require('../../emit')

function onsocket(socket,data){   
    //勾选的音效ids     
    var user = socket.handshake.cookies.authorized;
    //state:0=未审核 1=已审核 2=已发放
    data.user = user;
    data.state = 0;
    orderdb.createorder(user, data, function(err){
        if(config.debug){
            logger.log(err);
        }
        else{
            if(err){
                logger.log(err);
                emit.send(socket,'createorder', 0);
            }else{
                removecartitem.onsocket(socket, data); 
                emit.send(socket,'createorder', 1);                
            }
        }
    });
}

module.exports = {
    onsocket
}